// hyb_yl/wodedingdan/wodedingdan.js
var app =getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    taocan: ["已支付", "待评价", "已评价"],
    currentTab: 0
  },
  // 点击切换套餐选项卡
  taocan: function (e) {
    var that =this
    var index = parseInt(e.currentTarget.dataset.index) 
    var openid = wx.getStorageSync('openid');
    //console.log(index)
    if (index == 0) {
     // console.log('已支付')
      app.util.request({
        'url': 'entry/wxapp/Allordersyi',
        "data": {
          openid: openid
        },
        success: function (res) {
          //console.log(res)
          that.setData({
            dingdan: res.data.data
          })
        },
        fail: function (err) {
          console.log(err)
        },
      })
    }
    if (index == 1) {
     console.log('待评价')
      var openid =wx.getStorageSync('openid')
      app.util.request({
        'url': 'entry/wxapp/Allorderspingj',
        "data": {
          openid: openid
        },
        success: function (res) {
          console.log(res)
          that.setData({
            dingdan: res.data.data,
            index: index
          })
        },
        fail: function (err) {
          console.log(err)
        },
      })
    }
    if (index == 2) {
      //console.log('已评价')
      var openid = wx.getStorageSync('openid')
      app.util.request({
        'url': 'entry/wxapp/Allordersypj',
        "data": {
          openid: openid
        },
        success: function (res) {
          console.log(res)
          that.setData({
            dingdan: res.data.data,
            index: index
          })
        },
        fail: function (err) {
          console.log(err)
        },
      })
    }

    this.setData({
      currentTab: e.currentTarget.dataset.index + 1
    })
  },
  taocan1: function (e) {
    var that = this
    var openid = wx.getStorageSync('openid');
    app.util.request({
      'url': 'entry/wxapp/Allorders',
      "data": {
        openid: openid
      },
      success: function (res) {
        //console.log(res)
        that.setData({
          dingdan: res.data.data
        })
      },
      fail: function (err) {
        console.log(err)
      },
    })  
    var index = e.currentTarget.dataset.index
    //console.log(index)
    this.setData({
      currentTab: 0
    })
  },

  deleteProduct:function(e){
    let that = this;
    let i=e.currentTarget.dataset.index;
    let dingdan = that.data.dingdan;
    var id = e.currentTarget.dataset.id;
    var openid= wx.getStorageSync('openid')
    console.log(id)
    var uniacid = app.siteInfo.uniacid;
    dingdan.splice(i,1);
    app.util.request({
      'url': 'entry/wxapp/Delvideo',
      "data": {
        id: id,
        uniacid: uniacid,
        openid:openid
      },
      success: function (res) {
        console.log(res)
      },
      fail: function (err) {
        console.log(err)
      },
    })


    that.setData({
      dingdan: dingdan
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var that =this
     var openid =wx.getStorageSync('openid');
     app.util.request({
       'url': 'entry/wxapp/Allorders',
       "data": {
         openid: openid
       },
       success: function (res) {
         console.log(res)
         that.setData({
           dingdan: res.data.data
         })
       },
       fail: function (err) {
         console.log(err)
       },
     })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    var openid = wx.getStorageSync('openid');
    app.util.request({
      'url': 'entry/wxapp/Allorders',
      "data": {
        openid: openid
      },
      success: function (res) {
        console.log(res)
        that.setData({
          dingdan: res.data.data
        })
      },
      fail: function (err) {
        console.log(err)
      },
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  pingjia:function(e){
    var id = e.currentTarget.dataset.id;
    var sroomtitle = e.currentTarget.dataset.data;
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/jibingxq/jibingxq?id=' + e.currentTarget.dataset.id + '&sroomtitle=' + sroomtitle,
    })
  }
})